//
//  BaseTableViewController.swift
//  Weibo
//
//  Created by 赵志文 on 15/11/22.
//  Copyright © 2015年 zzw. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {
    
    //用户登录标记
    var userLogOn = false
    
    var visitorView: VisitorView?
    
    
    //创建视图
    /**
    如果视图不存在，系统就会再次调用LoadView这个函数
    */
    override func loadView() {
//        print(view)
        userLogOn ? super.loadView():setUpVistorView()
        
    }
    /**
    设置访客视图
    */
    private func setUpVistorView(){
        
        visitorView = VisitorView()
        
//        visitorView?.delegate = self
        //替换根视图(细节----坑死我了)
        view = visitorView
//        
        visitorView!.loginButton.addTarget(self, action: "visitorViewWillLogin", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView!.registButton.addTarget(self, action: "visitorViewWillRegester", forControlEvents: UIControlEvents.TouchUpInside)
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewWillRegester")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewWillLogin")
        
    }
    
    @objc private func visitorViewWillLogin() {
        print("登录")
        let navVc = UINavigationController(rootViewController: OAuthViewController())
        presentViewController(navVc, animated: true, completion: nil)
    }
    @objc private func visitorViewWillRegester() {
        print("注册")
    }

}
